﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using PasswordProvider.ViewModel.Properties;
using PasswordProvider.ViewModel.Framework;

namespace PasswordProvider.ViewModel
{
    public class BrowserOptionsViewModel : VisualViewModel, ICommitChanges
    {
        internal BrowserOptionsViewModel()
            : base(Strings.BrowserOptions_DisplayName, Strings.BrowserOptions_ToolTip)
        {
        }

        #region ICommitChanges

        /// <summary>
        /// Write the modified settings to the settings file.
        /// </summary>
        public void CommitChanges()
        {
            if (DoubleClickNavigatesToWebsite.IsChanged)
                Settings.Default.DoubleClickNavigatesToWebSite = DoubleClickNavigatesToWebsite.IsChecked;

            if (AlwaysUseInternetExplorer.IsChanged)
                Settings.Default.AlwaysUseInternetExplorer = AlwaysUseInternetExplorer.IsChecked;

            if (AttemptAutoFill.IsChanged)
                Settings.Default.AttemptAutoFill = AttemptAutoFill.IsChecked;

            Settings.Default.Save();
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// DoubleClickNavigatesToWebSite option
        /// </summary>
        public ToggleViewModel DoubleClickNavigatesToWebsite
        {
            get
            {
                if (_doubleClickNavigates == null)
                {
                    _doubleClickNavigates = new ToggleViewModel(
                        Strings.BrowserOptions_DoubleClickNavigatesToWebSite_DisplayName,
                        Strings.BrowserOptions_DoubleClickNavigatesToWebSite_ToolTip,
                        Settings.Default.DoubleClickNavigatesToWebSite);
                }
                return _doubleClickNavigates;
            }
        } private ToggleViewModel _doubleClickNavigates;

        /// <summary>
        /// AlwaysUseInternetExplorer option
        /// </summary>
        public ToggleViewModel AlwaysUseInternetExplorer
        {
            get
            {
                if (_alwaysUseInternetExplorer == null)
                {
                    _alwaysUseInternetExplorer = new ToggleViewModel(
                        Strings.BrowserOptions_AlwaysUseInternetExplorer_DisplayName,
                        Strings.BrowserOptions_AlwaysUseInternetExplorer_ToolTip,
                        Settings.Default.AlwaysUseInternetExplorer);
                }
                return _alwaysUseInternetExplorer;
            }
        } private ToggleViewModel _alwaysUseInternetExplorer;


        /// <summary>
        /// Not (opposite of) AlwaysUseInternetExplorer
        /// </summary>
        public ToggleViewModel UseDefaultBrowser
        {
            get
            {
                if (_useDefaultBrowser == null)
                {
                    _useDefaultBrowser = new ToggleViewModel(
                        Strings.BrowserOptions_UseDefaultBrowser_DisplayName,
                        Strings.BrowserOptions_UseDefaultBrowser_ToolTip,
                        !Settings.Default.AlwaysUseInternetExplorer);
                }
                return _useDefaultBrowser;
            }
        } private ToggleViewModel _useDefaultBrowser;
        
        /// <summary>
        /// AttemptAutoFill option
        /// </summary>
        public ToggleViewModel AttemptAutoFill
        {
            get
            {
                if (_attemptAutoFill == null)
                {
                    _attemptAutoFill = new ToggleViewModel(
                        Strings.BrowserOptions_AttemptAutoFill_DisplayName,
                        Strings.BrowserOptions_AlwaysUseInternetExplorer_ToolTip,
                        Settings.Default.AttemptAutoFill);
                }
                return _attemptAutoFill;
            }
        } private ToggleViewModel _attemptAutoFill;

        /// <summary>
        /// Explaination string
        /// </summary>
        public static string AttemptAutoFillExplanation
        {
            get 
            { 
                return Strings.BrowserOptions_AttemptAutoFill_Explaination;                
            }
        }

        #endregion // Public Properties
    }
}
